<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <!-- <link rel="stylesheet" type="text/css" href="{$_G['URL']['YX2020_CSS']}css/reset.css"> -->

    <script src="https://css2020.yixuan.net/2020css/yx2020/js/jquery.js?v=2"></script>
    <link rel="stylesheet" type="text/css" href="https://css2020.yixuan.net/2020css/yx2020/css/reset.css">
    <link rel="stylesheet" type="text/css" href="https://css2020.yixuan.net/2020css/yx2020/css/swiper.min.css">
    {if $config['weixinh5']==2}
    <script src="{$_G['URL']['YX2020_CSS']}js/vconsole.min.js"></script>
    <script> var vConsole = new VConsole(); </script>
    {/if}
    <script src="https://css2020.yixuan.net/2020css/yx2020/js/swiper-3.4.2.min.js"></script>
    <script src="{$_G['URL']['LOTTERY_CSS']}lottery/js/layer/layer.js"></script>
    <script>
        init();
        window.onresize = init;
        function init(){
            document.documentElement.style.fontSize =
                document.documentElement.clientWidth / 7.5 + 'px';
        }
    </script>
    <title>{$theme['title']}-选择{$course_other_name}</title>
    <style>
        body{
            padding-bottom: 1.13rem;
        }
        .wrap .content{
            background: #f7f7f7;
            padding-top: 0.14rem;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        .wrap .content .li{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            padding: 0.19rem 0.11rem 0.17rem;
            background: #ffffff;
            border-bottom: 0.01rem solid #f7f7f7;
        }
        .wrap .content .li .checkbox,.footer .checkbox{
            padding-left: 0.15rem;
            padding-right: 0.4rem;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-grow: 5;
        }
        .wrap .content .li .checkbox .checkbox_img,.footer .checkbox .checkbox_img{
            width: 0.22rem;
            height: 0.17rem;
            display: none;
        }
        .wrap .content .li .input,.footer .checkbox .input{
            width: 0.37rem;
            height: 0.37rem;
            border-radius: 0.37rem;
            background: #eee;
            border: 0.01rem solid #ccc;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .wrap .content .li input:checked+.input,.footer .checkbox input:checked+.input{
            background-image: linear-gradient(to top,#f8277a,#fe848d);
        }
        .wrap .content .li input:checked+.input .checkbox_img,.footer .checkbox input:checked+.input .checkbox_img{
            display: block;
        }
        .wrap .content .li input,.footer .checkbox input{
            display: none;
        }
        .wrap .content .head_img{
            max-width: 1.66rem;
            max-height: 1.66rem;
            border-radius: 0.14rem;
            flex-grow: 7;
        }
        .wrap .content .li .right{
            color: #999999;
            font-size: 0.24rem;
            padding-left: 0.4rem;
            flex-grow: 15;
            width: 4.2rem;
        }
        .wrap .content .li .right .tit{
            width: 4.2rem;
            color: #333333;
            font-size: 0.28rem;
            line-height: 1.6em;
            padding: 0.1rem 0;
        }
        .wrap .b_content .li .right .tit{
            line-height: 0.5rem;
        }

        .wrap .content .li .right .data{
            display: flex;
            justify-content: flex-start;
            padding-top: 0.16rem;
            line-height: 0.42rem;
        }
        .wrap .content .li .right .data .d_left,.wrap .content .li .right .data .d_right{
            display: flex;
            flex-direction: column;
        }
        .wrap .content .li .right .data .d_left{
            padding-right: 0.2rem;
            position: relative;
        }
        .wrap .content .li .right .data .d_left::after{
            content: "";
            position: absolute;
            top: 0;
            bottom: 0;
            right: 0;
            width: 0.01rem;
            min-width: 1px;
            height: 0.26rem;
            margin: auto;
            background: #eeeeee;
        }
        .wrap .content .li .right .data .d_right{
            padding-left: 0.2rem;
        }
        .wrap .content .li .right .data .d_right .dr_t{
            font-size: 0.28rem;
            color: #f91d76;
        }
        .wrap .content .li .right .data .d_right .dr_b{
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .wrap .content .li .right .data .d_right .dr_b img{
            width: 0.21rem;
            height: 0.21rem;
            margin-right: 0.07rem;
        }
        .wrap .content .li .right .name{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            margin-bottom: 0.1rem;
            margin-top: 0.1rem;
        }
        .wrap .content .li .right .name span{
            color: #5086ff;
            background: #ecf5ff;
            line-height: 0.32rem;
            padding: 0 0.08rem;
            font-size: 0.2rem;
            border-radius: 0.06rem;
        }
        .wrap .content .li .right .d_txt{
            color: #999999;
            font-size: 0.24rem;
            line-height: 0.38rem;
        }
        .wrap .content .li .right .d_txt span{
            font-size: 0.26rem;
            color: #f91d76;
        }

        .footer{
            position: fixed;
            bottom: 0;
            background: #ffffff;
            width: 7.5rem;
            left: 0;
            right: 0;
            box-shadow: 0 -0.1rem 0.2rem 0 rgba(200,200,200,0.5);
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 1.13rem;
            z-index: 2;
        }
        .footer .button{
            width: 3.86rem;
            height: 0.86rem;
            background:linear-gradient(to right,#f82079,#fe878e);
            color: #ffffff;
            font-size: 0.28rem;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-right: 0.26rem;
            border-radius: 0.2rem;
        }
        .footer .button a{
            color: #ffffff;
        }
        .footer .button img{
            width: 0.3rem;
            height: 0.3rem;
            margin-right: 0.12rem;
        }
        .footer .checkbox{
            padding: 0;
            padding-left: 0.2rem;
            width: 0.9rem;
            display: flex;
            flex-direction: column;
        }
        .footer .checkbox input{
            display: none;
        }
        .footer .checkbox span{
            font-size: 0.22rem;
            color: #999999;
            padding-top: 0.1rem;
        }
        .footer .data{
            width: 2.5rem;
            padding-left: 0.5rem;
            padding-right: 0.4rem;
        }
        .footer .data .top{
            font-size: 0.28rem;
            color: #333333;
        }
        .footer .data .top span{
            color: #f91d76;
        }
        .footer .data .bot{
            font-size: 0.24rem;
            color: #999999;
            font-style: italic;
        }
        .footer .data .bot span{
            color: #fa6397;
            text-decoration: underline;
            padding: 0 0.1rem;
        }


        .service{
            background: rgba(0,0,0,0.8);
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
            position: fixed;
            z-index: 3;
        }

        .service .box{
            width: 6.15rem;
            position: absolute;
            left: 0;
            right: 0;
            margin: auto;
            border-radius: 0.20rem;
            overflow: hidden;
            top: 50%;
            transform: translateY(-50%);
            background: #ffffff;
            max-height: calc(60vh + 2.8rem);
        }
        .service .box .head{
            height: 1.1rem;
            line-height: 1.1rem;
            text-align: center;
            background-image: linear-gradient(to right,#fe7e8c,#f8347d);
            color: #ffffff;
            font-size: 0.32rem;
            position: relative;
        }
        .service .box .head .close{
            width: 0.33rem;
            height: 0.33rem;
            position: absolute;
            right: 0.4rem;
            top: 0;
            bottom: 0;
            margin: auto;
        }
        .service .box .body{
            padding: 0 0.35rem;
            max-height: 60vh;
            overflow-y: auto;
        }
        .service .box .body .tips{
            line-height: 0.86rem;
            font-size: 0.26rem;
            color: #999999;
        }
        .service .box .body .item{
            padding: 0.3rem 0.32rem;
            line-height: 1.6em;
            background: #f7f7f7;
            border: 0.01rem solid #eeeeee;
            border-radius: 0.2rem;
            color: #333333;
            font-size: 0.28rem;
            margin-bottom: 0.28rem;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }
        .service .box .body .active{
            background-image: linear-gradient(to right,#fe7e8c,#f8347d);
            color: #ffffff;
        }
        .service .box .btn{
            font-size: 0.32rem;
            color: #f8357d;
            line-height: 1rem;
            text-align: center;
            margin-top: 0.7rem;
            border-top: 0.01rem solid #f7f7f7;
        }
    </style>
    <style>
        .right_span{
            position: absolute;
            right: 20px;
            color: #999999;
            font-size: .24rem;
            line-height: .38rem;
        }
    </style>
</head>
<body>
<div class="wrap">
    <div class="content">
        {loop $course_list $item}
        <label class="li">
            <div class="checkbox">
                <input type="checkbox" data-courseid="{$item['id']}" data-shangjia_id="{$item['shangjia_id']}">
                <div class="input">
<!--                    <img class="checkbox_img" src="{YX_LOCAL_PLUGIN_FISSION}/ok.png">-->
                    <img class="checkbox_img" src="{$_G['URL']['BEILAI_IMG']}/ok.png">
                </div>
            </div>
            <img class="head_img" src="{$item['top_img']}" alt="">
            <div class="right">
                <div class="tit">{$item['name']} </div>
                <div class="d_txt shangjia_name" data-shangjia_name="{$item['shangjia_name']}">机构:{$item['shangjia_name']}</div>
                {if $item['min_distance']}<div class="d_txt shangjia_name" >距离:{$item['min_distance']} KM</div>{/if}
                <div class="data">
                    <div class="d_left d_txt">
                        <div>价值：<span>￥{$item['price']}</span></div>
                    </div>
                    <div class="d_right">
                        <span class="dr_b">已购：{$item['selected_num']}</span>
                    </div>
                </div>
            </div>
        </label>

        <div class="service" style="display: none;">
            <div class="box">
                <div class="head">
                    <span>请确认{$school_other_name}</span>
<!--                    <img class="close" src="{YX_LOCAL_PLUGIN_FISSION}/close.png"/>-->
                    <img class="close" src="{$_G['URL']['BEILAI_IMG']}/close.png"/>
                </div>
                <div class="body">
                    <div class="tips" id="address_prev">点击选择{$school_other_name}</div>
                    {loop $item['address'] $address_item}
                    <div class="item">{$address_item}</div>
                    {/loop}
                </div>
                <div class="btn">确定</div>
            </div>
        </div>
        {/loop}
    </div>
    <div class="footer">
        <div class="data">
            <!--            可选择课程总数 {$course_num}-->
            <div class="top">已选<span id="choose_num">0</span>个</div>
            <div class="bot">最多选<span>{$course_max_num}</span>个{$course_other_name}</div>
        </div>
        <div class="button">
            <a href="javascript:goNext()"><span>下一步</span></a>
        </div>
    </div>


</div>
</body>
<script>
    let course_min_num="{$course_min_num}";
    let course_max_num="{$course_max_num}";
    let gift_total="{$gift_total}";
    $(".content .li .checkbox input").change(function(){
        let shangjia_id=$(this).data("shangjia_id");
        let index=$(".content .li .checkbox input").index(this);
        let length=$(".content .li .checkbox input:checked").length;
        for(let i=0;i<length;i++){
            if(index==$(".content .li .checkbox input").index($(".content .li .checkbox input:checked").eq(i)))continue;
            if(shangjia_id==$(".content .li .checkbox input:checked").eq(i).data("shangjia_id")){
                layer.msg(`同一商家只能选择一个课程`);
                $(this).removeProp('checked').removeAttr('checked');
                return;
            }
        }
        //增加最大数的判断
        if (length>course_max_num){
            let tmp_msg = '最多选择'+course_max_num+'个课程';
            layer.msg(tmp_msg);
            $(this).removeProp('checked').removeAttr('checked');
            return;
        }
        $("#choose_num").html($(".content .li .checkbox input:checked").length);
        if(!$(this).prop("checked")){
            $(".service").eq($(".content .li .checkbox input").index(this)).find(".active").removeClass("active");
            return;
        }
        // $(".service .body .item").remove();
        // $("#address_prev").after($(".address_box").eq($(".content .li .checkbox input").index(this)).html());
        if($(".service").eq($(".content .li .checkbox input").index(this)).find(".item").length>1){
            $(".service").eq($(".content .li .checkbox input").index(this)).show();
        }else{
            $(".service").eq($(".content .li .checkbox input").index(this)).find(".item").addClass("active");
        }
        $("#choose_num").html($(".content .li .checkbox input:checked").length);
    });
    $(".service .close").click(function(){
        if($(".service").eq($(".service .close").index($(this))).find(".item.active").length<=0){
            $(".content .li .checkbox input").eq($(".service .close").index($(this))).removeProp('checked').removeAttr('checked');
        }
        $(".service").hide();
    });
    $(".service .btn").click(function(){
        if($(".service").eq($(".service .btn").index($(this))).find(".item.active").length<=0){
            $(".content .li .checkbox input").eq($(".service .btn").index($(this))).removeProp('checked').removeAttr('checked');
        }
        $(".service").hide();
    });
    $(".service .body .item").click(function(){
        $(this).siblings(".item").removeClass("active");
        if($(this).hasClass("active")){
            $(this).removeClass("active");
        }else{
            $(this).addClass("active");
        }
    });
    // function goNext(){
    //     let length=$(".content .li .checkbox input:checked").length;
    //     if(length<course_min_num){
    //         alert(`最少选择${course_min_num}个`);
    //         return;
    //     }
    //     if(length>course_max_num){
    //         alert(`最多只能选择${course_max_num}个`);
    //         return;
    //     }
    //     let arr="[";
    //     for(let i=0;i<length;i++){
    //         if(i>0)arr+=",";
    //         let shangjia_id = $(".content .li .checkbox input:checked").eq(i).data("shangjia_id");
    //         arr+="['shangjia_id'=>"+shangjia_id;
    //         let courseid = $(".content .li .checkbox input:checked").eq(i).data("courseid");
    //         arr+=",'course_id'=>"+shangjia_id;
    //         let index=$(".content .li .checkbox input").index($(".content .li .checkbox input:checked").eq(i));
    //         let address=$(".service").eq(index).find(".item.active").html();
    //         arr+=",'address'=>"+address;
    //         arr+="]";
    //     }
    //     arr+="]";
    //     let url=`/{php echo createMobileUrl('index', array('themeid'=>$themeid,'do'=>'payconfirm','gift_ids'=>$gift_ids,'type'=>$type));}`;

    // }
    function goNext(){
        let length=$(".content .li .checkbox input:checked").length;
        if(length<course_min_num){
            layer.msg(`最少选择${course_min_num}个`);
            return;
        }
        if(length>course_max_num){
            layer.msg(`最多只能选择${course_max_num}个`);
            return;
        }
        let arr=[];
        for(let i=0;i<length;i++){
            let shangjia_id = $(".content .li .checkbox input:checked").eq(i).data("shangjia_id");
            let courseid = $(".content .li .checkbox input:checked").eq(i).data("courseid");
            let index=$(".content .li .checkbox input").index($(".content .li .checkbox input:checked").eq(i));
            let address=$(".service").eq(index).find(".item.active").html();
            let top_img=$(".content .li .head_img").eq(index).attr("src");
            let name=$(".content .li .tit").eq(index).html();
            let shangjia_name=$(".content .li .shangjia_name").eq(index).data("shangjia_name");
            arr.push({
                shangjia_id,courseid,address,top_img,name,shangjia_name
            });
        }
        let courseStr=JSON.stringify(arr);
        localStorage.setItem("course_address",courseStr);
        if (gift_total<1){
            let url=`/{php echo createMobileUrl('wx', array('themeid'=>$themeid,'from'=>'mobile','r'=>'beilai.index.payconfirm','joinid'=>$joinid,'recordid'=>$recordid));}`;
            window.location.href=url;
        }else{
            let url=`/{php echo createMobileUrl('wx', array('themeid'=>$themeid,'from'=>'mobile','r'=>'beilai.index.gift','joinid'=>$joinid,'recordid'=>$recordid));}`;
            window.location.href=url;
        }

    }
</script>
</html>
